package cn.edu.sgu.www.mhxysy.controller.exp;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.exp.GradeExpDTO;
import cn.edu.sgu.www.mhxysy.entity.exp.GradeExp;
import cn.edu.sgu.www.mhxysy.pager.exp.GradeExpPager;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.exp.GradeExpService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "等级经验管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/grade_exp", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class GradeExpController {

    private final GradeExpService gradeExpService;

    @Autowired
    public GradeExpController(GradeExpService gradeExpService) {
        this.gradeExpService = gradeExpService;
    }

    @ApiOperation("添加等级经验")
    @ApiOperationSupport(ignoreParameters = "id")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JsonResult<Void> insert(@Validated GradeExpDTO gradeExpDTO) {
        gradeExpService.insert(gradeExpDTO);

        return JsonResult.success(CustomMessages.INSERT_SUCCESS);
    }

    @ApiOperation("通过ID修改等级经验")
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public JsonResult<Void> updateById(@Validated GradeExpDTO gradeExpDTO) {
        gradeExpService.updateById(gradeExpDTO);

        return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
    }

    @ApiOperation("查询角色的等级经验")
    @RequestMapping(value = "/selectRoleExp", method = RequestMethod.GET)
    public JsonResult<GradeExp> selectRoleExp(
            @ApiParam(name = "grade", value = "角色等级", required = true)
            @NotNull(message = "角色等级" + CustomMessages.NOT_NULL) Integer grade) {
        GradeExp gradeExp = gradeExpService.selectRoleExp(grade);

        return JsonResult.success(null, gradeExp);
    }

    @ApiOperation("查询宠物的等级经验")
    @RequestMapping(value = "/selectChongwuExp", method = RequestMethod.GET)
    public JsonResult<GradeExp> selectChongwuExp(
            @ApiParam(name = "grade", value = "宠物等级", required = true)
            @NotNull(message = "宠物等级" + CustomMessages.NOT_NULL) Integer grade) {
        GradeExp gradeExp = gradeExpService.selectChongwuExp(grade);

        return JsonResult.success(null, gradeExp);
    }

    @ApiOperation("分页查询等级经验列表")
    @RequestMapping(value = "/selectByPage", method = RequestMethod.POST)
    public JsonResult<JsonPage<GradeExp>> selectByPage(GradeExpPager pager) {
        Page<GradeExp> page = gradeExpService.selectByPage(pager);

        return JsonResult.restPage(page);
    }

}